package org.jeecg.common.modules.doctor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.jeecg.common.modules.doctor.entity.DoctorExtend;
import org.jeecg.common.modules.doctor.mapper.DoctorExtendMapper;
import org.jeecg.common.modules.doctor.service.IDoctorExtendService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * @Description: 医生扩展信息（大字段）
 * @Author: jeecg-boot
 * @Date:   2020-08-12
 * @Version: V1.0
 */
@Service
public class DoctorExtendServiceImpl extends ServiceImpl<DoctorExtendMapper, DoctorExtend> implements IDoctorExtendService {

    @Override
    public DoctorExtend getByDoctorId(String doctorId) {
        LambdaQueryWrapper<DoctorExtend> query = Wrappers.lambdaQuery();
        query.eq(DoctorExtend::getDoctorId,doctorId);
        return getOne(query);
    }

    @Override
    public List<DoctorExtend> getByDoctorIds(List<String> doctorIds) {
        if (CollectionUtils.isEmpty(doctorIds)){
            return Lists.newArrayList();
        }
        LambdaQueryWrapper<DoctorExtend> query = Wrappers.lambdaQuery();
        query.in(DoctorExtend::getDoctorId,doctorIds);
        return list(query);
    }

    @Override
    public DoctorExtend initDoctorExtend(String doctorId, String accessToken) {
        DoctorExtend doctorExtend =  new DoctorExtend();
        doctorExtend.setDoctorId(doctorId);
        doctorExtend.setAccessToken(accessToken);
        save(doctorExtend);
        return doctorExtend;
    }
    @Override
    public DoctorExtend getByAccessToken(String accessToken){
        DoctorExtend doctorExtend =  new DoctorExtend();
        doctorExtend.setAccessToken(accessToken);
        return getOne(Wrappers.lambdaQuery(doctorExtend));
    }
}
